package com.tqz.dt.advisor;

import com.tqz.dt.interceptors.GlobalTransactionalInterceptor;
import lombok.Data;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Advisor;

import java.lang.reflect.Method;

/**
 * <p>属性源通知
 *
 * @author tianqingzhao
 * @since 2021/7/7 15:42
 */
@Data
public class GlobalTransactionAttributeSourceAdvisor implements Advisor {

    private Advice advice;

    @Override
    public Advice getAdvice() {
        return this.advice;
    }

    @Override
    public boolean isPerInstance() {
        return true;
    }

    public boolean matches(Method method, Class<?> targetClass) {
        return ((GlobalTransactionalInterceptor) advice).getAngleTransactionAttributeSource().getTransactionAttribute(method, targetClass) != null;
    }
}
